from config.all_paths import config_variable_path
from config.global_variable import SIP
from utils.file_handling.txt_handling import extract_txt


def SIPDataProcessing(data, res):
    """
    SIP通话数据处理
    """
    # 所有片区
    if data.get('case_name') == '获取昨日外呼总数量':
        total_all = str(res.json()['data']['total'])
        SIP['totalSip']['total_all'] = total_all
    elif data.get('case_name') == '获取昨日外呼接通成功数量':
        Successfully_connected = str(res.json()['data']['total'])
        SIP['totalSip']['Successfully_connected'] = Successfully_connected
    elif data.get('case_name') == '获取昨日外呼无人接听数量':
        no_answer = str(res.json()['data']['total'])
        SIP['totalSip']['no_answer'] = no_answer
    elif data.get('case_name') == '获取昨日外呼中断呼叫数量':
        interrupt_call = str(res.json()['data']['total'])
        SIP['totalSip']['interrupt_call'] = interrupt_call
    elif data.get('case_name') == '获取昨日外呼呼叫失败数量':
        call_failure = str(res.json()['data']['total'])
        SIP['totalSip']['call_failure'] = call_failure

    # 长春
    elif data.get('case_name') == '获取昨日长春外呼总数量':
        total_all = str(res.json()['data']['total'])
        SIP['areaSip']['changchu']['total_all'] = total_all
    elif data.get('case_name') == '获取昨日长春外呼接通成功数量':
        Successfully_connected = str(res.json()['data']['total'])
        SIP['areaSip']['changchu']['Successfully_connected'] = Successfully_connected
    elif data.get('case_name') == '获取昨日长春外呼无人接听数量':
        no_answer = str(res.json()['data']['total'])
        SIP['areaSip']['changchu']['no_answer'] = no_answer
    elif data.get('case_name') == '获取昨日长春外呼中断呼叫数量':
        interrupt_call = str(res.json()['data']['total'])
        SIP['areaSip']['changchu']['interrupt_call'] = interrupt_call
    elif data.get('case_name') == '获取昨日长春外呼呼叫失败数量':
        call_failure = str(res.json()['data']['total'])
        SIP['areaSip']['changchu']['call_failure'] = call_failure

    # 广州
    elif data.get('case_name') == '获取昨日广州外呼总数量':
        total_all = str(res.json()['data']['total'])
        SIP['areaSip']['guangzhou']['total_all'] = total_all
    elif data.get('case_name') == '获取昨日广州外呼接通成功数量':
        Successfully_connected = str(res.json()['data']['total'])
        SIP['areaSip']['guangzhou']['Successfully_connected'] = Successfully_connected
    elif data.get('case_name') == '获取昨日广州外呼无人接听数量':
        no_answer = str(res.json()['data']['total'])
        SIP['areaSip']['guangzhou']['no_answer'] = no_answer
    elif data.get('case_name') == '获取昨日广州外呼中断呼叫数量':
        interrupt_call = str(res.json()['data']['total'])
        SIP['areaSip']['guangzhou']['interrupt_call'] = interrupt_call
    elif data.get('case_name') == '获取昨日广州外呼呼叫失败数量':
        call_failure = str(res.json()['data']['total'])
        SIP['areaSip']['guangzhou']['call_failure'] = call_failure

    # 成都
    elif data.get('case_name') == '获取昨日成都外呼总数量':
        total_all = str(res.json()['data']['total'])
        SIP['areaSip']['chengdu']['total_all'] = total_all
    elif data.get('case_name') == '获取昨日成都外呼接通成功数量':
        Successfully_connected = str(res.json()['data']['total'])
        SIP['areaSip']['chengdu']['Successfully_connected'] = Successfully_connected
    elif data.get('case_name') == '获取昨日成都外呼无人接听数量':
        no_answer = str(res.json()['data']['total'])
        SIP['areaSip']['chengdu']['no_answer'] = no_answer
    elif data.get('case_name') == '获取昨日成都外呼中断呼叫数量':
        interrupt_call = str(res.json()['data']['total'])
        SIP['areaSip']['chengdu']['interrupt_call'] = interrupt_call
    elif data.get('case_name') == '获取昨日成都外呼呼叫失败数量':
        call_failure = str(res.json()['data']['total'])
        SIP['areaSip']['chengdu']['call_failure'] = call_failure

    # 合肥
    elif data.get('case_name') == '获取昨日合肥外呼总数量':
        total_all = str(res.json()['data']['total'])
        SIP['areaSip']['hefei']['total_all'] = total_all
    elif data.get('case_name') == '获取昨日合肥外呼接通成功数量':
        Successfully_connected = str(res.json()['data']['total'])
        SIP['areaSip']['hefei']['Successfully_connected'] = Successfully_connected
    elif data.get('case_name') == '获取昨日合肥外呼无人接听数量':
        no_answer = str(res.json()['data']['total'])
        SIP['areaSip']['hefei']['no_answer'] = no_answer
    elif data.get('case_name') == '获取昨日合肥外呼中断呼叫数量':
        interrupt_call = str(res.json()['data']['total'])
        SIP['areaSip']['hefei']['interrupt_call'] = interrupt_call
    elif data.get('case_name') == '获取昨日合肥外呼呼叫失败数量':
        call_failure = str(res.json()['data']['total'])
        SIP['areaSip']['hefei']['call_failure'] = call_failure

    extract_txt(config_variable_path, str(SIP))

